package com.ptit.giaothong;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class HeightScores extends ListActivity {
	JSONParser jParser = new JSONParser();

	ArrayList<ItemScores> listScores;

	private Activity activity;

	public HeightScores(Activity activity) {
		this.activity = activity;
	}

	public void init() {
		MainActivity.keypage = 1;
		activity.setContentView(R.layout.heightscores);
		GlobalData global = new GlobalData();

		listScores = (ArrayList<ItemScores>) global.getHeightScores();
		ListView listview = (ListView) activity.findViewById(R.id.listView_id);

		ItemAdapter itemAdapter = new ItemAdapter(activity,
				R.layout.itemscores, listScores);
		listview.setAdapter(itemAdapter);
		// new LoadAllProducts().execute();
	}

	class ItemAdapter extends ArrayAdapter<ItemScores> {
		private int resource;
		private LayoutInflater layoutInflater;

		public ItemAdapter(Context mContext, int resource,
				List<ItemScores> models) {
			super(mContext, resource, models);
			this.resource = resource;
			layoutInflater = LayoutInflater.from(mContext);
		}

		public class ViewHolder {
			public TextView stt;
			public TextView name;
			public TextView diem;
			public TextView time;
			public TextView date;
			public LinearLayout linearLayout;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			ViewHolder viewHolder;
			if (convertView == null) {
				viewHolder = new ViewHolder();
				convertView = layoutInflater.inflate(resource, null, true);

				viewHolder.stt = (TextView) convertView
						.findViewById(R.id.stt_id);
				viewHolder.linearLayout = (LinearLayout) convertView
						.findViewById(R.id.liner_height_id);
				viewHolder.name = (TextView) convertView
						.findViewById(R.id.name_id);
				viewHolder.diem = (TextView) convertView
						.findViewById(R.id.scores_id);
				viewHolder.time = (TextView) convertView
						.findViewById(R.id.time_id);
				viewHolder.date = (TextView) convertView
						.findViewById(R.id.date);

				convertView.setTag(viewHolder);

			} else {
				viewHolder = (ViewHolder) convertView.getTag();
			}
			ItemScores item = getItem(position);

			viewHolder.stt.setText(String.valueOf(item.getStt()));
			viewHolder.name.setText(item.getName());
			viewHolder.diem.setText(item.getScores()+"");
			viewHolder.time.setText(item.getDatetime());
			viewHolder.date.setText(item.getDatetime());
			return convertView;
		}
	}

}